package com.base.api.controller.userinfo;

import com.base.exception.BaseException;
import com.base.mapper.voipmapper.UserAuthInfoMapper;
import com.base.po.voip.Subscribers;
import com.base.po.voip.UserAuthInfo;
import com.base.result.ResponseResult;
import com.base.result.ResponseResultUtils;
import com.base.service.SubscribersService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Optional;

@Api(tags ="根据ID返回用户真实名称和手机号")
@RequestMapping("/userinfo")
@Slf4j
@RestController
public class WebSearchUserInfoController {

    private final UserAuthInfoMapper userAuthInfoMapper;

    private final SubscribersService subscribersService;

    public WebSearchUserInfoController(UserAuthInfoMapper userAuthInfoMapper, SubscribersService subscribersService) {
        this.userAuthInfoMapper = userAuthInfoMapper;
        this.subscribersService = subscribersService;
    }

    @PostMapping("/getByUserId")
    public ResponseResult getByUserId(@ApiParam("用户ID") @RequestParam String userId){
        Subscribers subscribers=  Optional.ofNullable(subscribersService.selectByPrimaryKey(userId)).orElseThrow(()->new  BaseException(ResponseResultUtils.getResponseResultDataS("用户不存在")));
        UserAuthInfo userAuthInfo=Optional.ofNullable(userAuthInfoMapper.findUserAuthInfoById(userId)).orElse(new UserAuthInfo());
        String reultMsg=subscribers.getMobile()+Optional.ofNullable(userAuthInfo.getUserRealName()).orElse("该用户未填写真实姓名");
        return ResponseResultUtils.getResponseResultDataS(reultMsg);
    }
}
